//
//  HZPersonageView.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/4.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZPersonageView.h"

@interface HZPersonageView()

@property(nonatomic,strong)UIImageView*  icon;
@property(nonatomic,strong)UILabel*  nameLabel;
@property(nonatomic,strong)UIButton*  basicInfoButton;

@end

@implementation HZPersonageView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置并添加子控件
        [self setupUI];
    }
    return self;
}

#pragma mark -
#pragma mark    设置并添加子控件
-(void)setupUI{
    
    self.backgroundColor = [UIColor colorWithRed:0/255.0 green:198/255.0 blue:199/255.0 alpha:1];
    
    //添加
    [self addSubview:self.icon];
    [self addSubview:self.nameLabel];
    [self addSubview: self.basicInfoButton];
    
    
    //约束
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(25);
        make.leading.equalTo(20);
        make.height.equalTo(60);
        make.width.equalTo(60);
    }];

    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.icon);
        make.leading.equalTo(self.icon.trailing).offset(15);
    }];
    
    [self.basicInfoButton makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.icon);
        make.leading.equalTo(self.icon.trailing).offset(15);
        
    }];
    
}






#pragma mark -
#pragma mark     懒加载
-(UIImageView *)icon{
    if (!_icon) {
        
        _icon = [[UIImageView alloc]init];
        
        _icon.image = [UIImage imageNamed:@"name"];
    }
    return _icon;
}

-(UILabel *)nameLabel{
    if (!_nameLabel) {
        
        _nameLabel = [[UILabel alloc]init];
        
        _nameLabel.text = @"XXX";
        _nameLabel.textColor = [UIColor whiteColor];
        [_nameLabel sizeToFit];
    }
    return _nameLabel;
}



-(UIButton *)basicInfoButton{
    if (!_basicInfoButton) {
        
        _basicInfoButton = [[UIButton alloc]init];
        
        [_basicInfoButton setTitle:@"基本资料信息" forState:UIControlStateNormal];
        
        //关联方法
        [_basicInfoButton addTarget:self action:@selector(didClickbasicInfoButton) forControlEvents:UIControlEventTouchUpInside];
        
        _basicInfoButton.tintColor = [UIColor whiteColor];
        
        _basicInfoButton.titleLabel.font = [UIFont systemFontOfSize:13];
        
        [_basicInfoButton sizeToFit];
        
    }
    return _basicInfoButton;
}


#pragma mark -
#pragma mark  点击基本资料信息按钮
-(void)didClickbasicInfoButton{
    
    NSLog(@"基本资料信息按钮被点击了");
    if (self.pushInfoVC != nil) {
        //调用block
        self.pushInfoVC();
    }
    
    
    
    
}






@end
